<?php

	class source
	{

		var $fw		= null;
		var $sec	= null;

		function source(&$framework, &$security)
		{

			$this->fw	= &$framework;
			$this->sec	= &$security;

			$this->fw->pc_item('Members', 'View a list of active members', 'index.php?what=members');

			switch($this->fw->do)
			{

				case 'whos_online':
					$this->show_whos_online();
					break;

				// Borrowing
				case 'borrow':

					break;

				// Other

				case 'wishlist':
					$this->show_member_wishlist();
					break;

				case 'collection':
					$this->show_member_collection();
					break;

				default:
					$this->list_members();
					break;

			}

		}

		function list_members()
		{

			// Display a list of active/approved members (if current user is administrator they will have admin functions as well)

			$this->fw->template	= 'members.list.tpl';

			$filter	= trim(@$_REQUEST['filter']);
			$search	= trim(@$_REQUEST['search']);

			// pagination
			$members	= $this->fw->get_members(1, 1, true, $filter, $search);
			$num		= count($members);
			$pagin		= $this->fw->pagination($num);

			if(is_array($members)) {
				$members	= array_splice($members, $pagin['start'], $pagin['limit']);
			}

			$this->fw->content['members']		= $members;
			$this->fw->content['pagination']	= $pagin;
			$this->fw->content['filter']		= $filter;
			$this->fw->content['search']		= htmlentities($search);

			$this->fw->content['alpha_base']	= 'index.php?what=members';

		}

		function show_member_collection()
		{

			// Display the entire collection of the selected member
			$member_id	= (int)$_REQUEST['id'];

			$member		= $this->fw->get_member_details($member_id);

			if($member_id == $this->sec->dtls['id'])
			{

				header('location: index.php?what=mymovies');
				exit;

			}

			if($member)
			{

				$this->fw->pc_item('View '. $member['username'] .'\'s Collection', 'View the movies currently in '. $member['username'] .'\'s collection');

				$this->fw->template				= 'members.collection.tpl';

				$filter	= trim(@$_REQUEST['filter']);
				$genre	= trim(@$_REQUEST['genre']);
				$search	= trim(@$_REQUEST['search']);

				//pagination
				$movies	= $this->fw->get_member_movies($member_id, $filter, $search, $genre);
				$num	= count($movies);
				$pagin	= $this->fw->pagination($num);

				if(is_array($movies)) {
					$movies	= array_splice($movies, $pagin['start'], $pagin['limit']);
				}

				$this->fw->content['movies']		= $movies;
				$this->fw->content['pagination']	= $pagin;
				$this->fw->content['member']		= $member;
				$this->fw->content['filter']		= $filter;
				$this->fw->content['genre']			= $genre;
				$this->fw->content['search']		= htmlentities($search);

			}
			else
			{

				header('location: index.php?what=members');

			}

		}

		function show_member_wishlist()
		{

			// Display the entire collection of the selected member
			$member_id	= (int)$_REQUEST['id'];

			$member		= $this->fw->get_member_details($member_id);

			if($member_id == $this->sec->dtls['id'])
			{

				header('location: index.php?what=wishlist');
				exit;

			}

			if($member) {
				$this->fw->pc_item('View '. $member['username'] .'\'s Wishlist', 'View the movies currently in '. $member['username'] .'\'s Wishlist');

				$this->fw->template				= 'members.wishlist.tpl';

				$filter	= trim(@$_REQUEST['filter']);
				$genre	= trim(@$_REQUEST['genre']);
				$search	= trim(@$_REQUEST['search']);

				// pagination
				$movies	= $this->fw->get_member_wishlist($member_id, $filter, $search, $genre);
				$num	= count($movies);
				$pagin	= $this->fw->pagination($num);

				if(is_array($movies)) {
					$movies	= array_splice($movies, $pagin['start'], $pagin['limit']);
				}

				$this->fw->content['movies']		= $movies;
				$this->fw->content['pagination']	= $pagin;
				$this->fw->content['member']		= $member;
				$this->fw->content['filter']		= $filter;
				$this->fw->content['genre']			= $genre;
				$this->fw->content['search']		= htmlentities($search);

			} else {
				header('location: index.php?what=members');
			}

		}

		function show_whos_online()
		{

			$this->fw->pc_item('Who\'s Online', 'A list of members who have been logged in within the last 15 minutes.');
			$this->fw->template	= 'members.whos_online.tpl';

			$members	= $this->fw->get_whos_online();

			$this->fw->content['members']	= $members;

		}

	}

?>